import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Form, Input, Button } from '@/components/AntdMobile';
import { http } from '@/apis/http';
import { useNavigate } from 'react-router-dom';
const Login = () => {
    const navigate = useNavigate();
    const onFinish = async (values) => {
        console.log('Success:', values);
        const res = await http.post('/login', values);
        console.log(res);
        if (res.code === 200) {
            localStorage.setItem('token', res.token);
            navigate('/home/1');
        }
    };
    const validatePassword = async (_, value) => {
        // const passwordReg = /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/;
        if (!value) {
            return Promise.reject(new Error('密码不能为空'));
        }
        // if (!passwordReg.test(value)) {
        //   return Promise.reject(new Error('密码需至少8位，包含字母和数字'));
        // }
        return Promise.resolve();
    };
    return (_jsx(_Fragment, { children: _jsxs(Form, { className: "pt50", layout: "horizontal", onFinish: onFinish, footer: _jsx(Button, { block: true, type: "submit", shape: "rounded", color: "primary", size: "large", children: "\u63D0\u4EA4" }), children: [_jsx(Form.Item, { name: "username", label: "\u7528\u6237\u540D1", rules: [{ required: true, message: '姓名不能为空' }], children: _jsx(Input, {}) }), _jsx(Form.Item, { name: "password", label: "\u5BC6\u7801", rules: [{ validator: validatePassword }], children: _jsx(Input, { placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801", clearable: true, type: 'password' }) })] }) }));
};
export default Login;
